﻿
Partial Class App_MediaUpload
    Inherits MyUI.PageBaseApp

    Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load


        If UI.Page.GetValueInt("id") <> 0 Then

            Dim m = DB.TAB.Media.GetByPK(UI.Page.GetValue("id"))

            If m Is Nothing Then
                Response.ContentType = "image/png"
                Response.WriteFile(Server.MapPath("/Style/app/Img/noimage.png"))
            Else
                Response.ContentType = "image/" & IO.Path.GetExtension(m.App_Url).Replace(".", "")
                Response.WriteFile(m.FullPathMedia)

            End If

        Else

            Dim ss As IO.Stream
            If Request.Files.Count > 0 Then
                ss = Request.Files(0).InputStream
            Else
                ss = Request.GetBufferlessInputStream
            End If

            Dim m As New mDB.Media With {.User_Id = CurrUser.Id}
            DB.InsertOnSubmit(m)
            DB.SubmitChanges()

            m.AttachMedia(UI.Page.GetValue("qqfile"), ss)


            Response.ContentType = "application/json"
            Response.Write("{""success"": true,""image_id"":" & m.Id & "}")
            Response.End()

        End If


    End Sub





End Class
